package com.ruoyi.web.controller.Base;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.domain.AbilityPath;
import com.ruoyi.service.IAbilityPathService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 路由Controller
 * 
 * @author ruoyi
 * @date 2024-09-03
 */
@RestController
@RequestMapping("/system/path")
public class AbilityPathController extends BaseController
{
    @Autowired
    private IAbilityPathService abilityPathService;

    /**
     * 查询路由列表
     */
    @PreAuthorize("@ss.hasPermi('system:path:list')")
    @GetMapping("/list")
    public TableDataInfo list(AbilityPath abilityPath)
    {
        startPage();
        List<AbilityPath> list = abilityPathService.selectAbilityPathList(abilityPath);
        return getDataTable(list);
    }

    public TableDataInfo liar(AbilityPath abilityPath)
    {
        startPage();
        List<AbilityPath> list = abilityPathService.selectAbilityPathList(abilityPath);
        return getDataTable(list);
    }

    /**
     * 导出路由列表
     */
    @PreAuthorize("@ss.hasPermi('system:path:export')")
    @Log(title = "路由", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AbilityPath abilityPath)
    {
        List<AbilityPath> list = abilityPathService.selectAbilityPathList(abilityPath);
        ExcelUtil<AbilityPath> util = new ExcelUtil<AbilityPath>(AbilityPath.class);
        util.exportExcel(response, list, "路由数据");
    }

    /**
     * 获取路由详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:path:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(abilityPathService.selectAbilityPathById(id));
    }

    /**
     * 新增路由
     */
    @PreAuthorize("@ss.hasPermi('system:path:add')")
    @Log(title = "路由", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AbilityPath abilityPath)
    {
        return toAjax(abilityPathService.insertAbilityPath(abilityPath));
    }

    /**
     * 修改路由
     */
    @PreAuthorize("@ss.hasPermi('system:path:edit')")
    @Log(title = "路由", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AbilityPath abilityPath)
    {
        return toAjax(abilityPathService.updateAbilityPath(abilityPath));
    }

    /**
     * 删除路由
     */
    @PreAuthorize("@ss.hasPermi('system:path:remove')")
    @Log(title = "路由", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(abilityPathService.deleteAbilityPathByIds(ids));
    }
}
